package com.ztjy.purchase.biz.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ztjy.bean.CType;
import com.ztjy.purchase.biz.CTypeBiz;
import com.ztjy.purchase.dao.CTypeDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CTypeBizImpl implements CTypeBiz {
    @Autowired
    private CTypeDao tdao;
    @Override
    public CType findCTypeByTid(Integer tid) {
        return tdao.selectByPrimaryKey(tid);
    }

    @Override
    public PageInfo<CType> findAllCType(CType cType, Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<CType> allCType = tdao.findAllCType(cType);
        PageInfo<CType> pageInfo=new PageInfo<CType>(allCType);
        return pageInfo;
    }

    @Override
    public List<CType> findAllCType() {
        CType cType = new CType();
        cType.setTypeStatus(1);
        return tdao.findAllCType(cType);
    }

    @Override
    public boolean addCType(CType cType) {
        boolean flag=false;
        try {
            flag = tdao.insertSelective(cType);
        }catch (Exception e){
            e.printStackTrace();
            flag=false;
        }
        return flag;
    }

    @Override
    public boolean updateCType(CType cType) {
        boolean flag=false;
        try {
            flag=tdao.updateByPrimaryKeySelective(cType);
        }catch (Exception e){
            e.printStackTrace();
            flag=false;
        }
        return flag;
    }

    @Override
    public List<CType> findCTypesByBId(Integer bid) {
        return tdao.findCTypesByBId(bid);
    }
}
